const express = require('express')
const {
	funcVerify,
} = require('../utils')
const Response = require('../modules/Response')

const router = express.Router()

// /cms/page/index
router.get('/page/index', function(req, res, next) {
	if (req.session._uid && req.session._userInfo) {
		return res.redirect('/dist/pages/main.html')
	}
	return res.redirect('/dist/pages/login.html')
})

// /cms/page/user
router.get('/page/user', function(req, res, next) {
	if (!funcVerify(req, 'user_list'))
		return res.type('json').send(new Response('201', '没有[user_list]权限'))
	return res.redirect('/dist/pages/user.html')
})

// /cms/page/role
router.get('/page/role', function(req, res, next) {
	if (!funcVerify(req, 'role_list'))
		return res.type('json').send(new Response('201', '没有[role_list]权限'))
	return res.redirect('/dist/pages/role.html')
})

// /cms/page/func
router.get('/page/func', function(req, res, next) {
	if (!funcVerify(req, 'func_list'))
		return res.type('json').send(new Response('201', '没有[func_list]权限'))
	return res.redirect('/dist/pages/func.html')
})

module.exports = router